package com.nightpiter.view.drawer;

import java.util.ArrayList;

import com.nightpiter.model.MetroModelData;
import com.nightpiter.model.objects.Station;
import com.nightpiter.model.objects.Transfer;
import com.nightpiter.model.objects.Tunnel;
import com.nightpiter.view.Calculator;
import com.nightpiter.view.Calculator.Mode;
import com.nightpiter.view.graphics.Canvas;
import com.nightpiter.view.graphics.Point;
import com.nightpiter.view.graphics.Rect;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * @author Ilya Shurigyn (honorik@gmail.com)
 */
public abstract class MetroDrawer {

	/** the model to be drawn */
	protected MetroModelData modelData;

	/** drawing mode */
	protected Mode mode;

	/** drawer properties */
	protected Property[] properties;

	private boolean ready = false;

	public Property[] getProperties() {
		return properties;
	}

	@SuppressWarnings("unused")
	private void setProperty(String name, String value) {
		for (Property property : properties) {
			if (property.getName().equalsIgnoreCase(name)) {
				property.setCurrentValue(value);
			}
		}

	}

	public void setProperties(Property[] properties) {
		this.properties = properties;
	}

	public final boolean prepare(MetroModelData modelData, Mode mode) {
		this.modelData = modelData;
		this.mode = mode;
		this.properties = new Property[0];

		internalPrepare();

		this.ready = true;
		return true;
	}
	
	public boolean update(Station station) {
		return false;
	}

	public final void drawMetro(Canvas canvas, Calculator calculator) {
		if (this.isReady()) {
			this.internalDrawMetro(canvas, calculator);
		}
	}

	protected boolean internalPrepare() {
		return true;
	};

	protected abstract void internalDrawMetro(Canvas canvas,
			Calculator calculator);

	public abstract Station[] searchStation(Point point, Calculator calculator);

	public abstract Rect getBounds();

	public abstract void selectStation(Station station, Canvas canvas,
			Calculator calculator);

	public abstract void showWay(ArrayList<Tunnel> selectedTunnels,
			ArrayList<Transfer> selectedTransfers,
			ArrayList<Station> selectedStations, Canvas canvas,
			Calculator calculator);

	/**
	 * @return the ready
	 */
	public boolean isReady() {
		return ready;
	}

}
